Repository navigation
fix(libcontainer): enforce check_proc_mount across all mount types and normalize destination - #3860
Closed
inanna-malick wants to merge 1 commit into
Closed
inanna-malick wants to merge 1 commit into
inanna-malick wants to merge 1 commit into
Conversation
…d normalize destination
In Mount::setup_mount(), check_proc_mount() was only called inside the
Some("proc" | "sysfs") match arm and skipped in the wildcard _ => arm
used by bind, tmpfs, and other mount types. Additionally,
check_proc_mount() joined mount.destination() without normalizing '.' or
'..' segments first.
Call check_proc_mount() in the _ => arm of setup_mount() as well, and
normalize mount.destination() in check_proc_mount() and the /dev
comparison.
Signed-off-by: Inanna Malick <inanna@recursion.wtf>
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
The /proc restriction can be bypassed through symlinks or cgroup mounts, lexical normalization can make read-only mounts writable, and the regression test can pass on unrelated failures.
4 open issues
What changed in this PR
This PR strengthens mount-destination validation in libcontainer by extending /proc checks and normalizing paths before policy comparisons.
Changes:
- Adds
/procvalidation to the fallback mount-type branch, including bind and tmpfs mounts. - Normalizes destinations for
/procchecks and the/devread-only exception. - Adds a regression test for direct and unnormalized destinations under
/proc.
| File | Description |
|---|---|
crates/libcontainer/src/rootfs/mount.rs |
Extends mount validation, normalizes destination comparisons, and adds regression coverage. |
Review effort: Balanced
| } | ||
| _ => { | ||
| if mount.destination() == Path::new("/dev") { | ||
| self.check_proc_mount(options.root, mount)?; |
Comment on lines
+225
to
226
| if Path::new(mount.destination()).normalize() == Path::new("/dev") { | ||
| mount_option_config.flags &= !MsFlags::MS_RDONLY; |
| MountError::Other(err.into()) | ||
| })?; | ||
| let dest_path = rootfs | ||
| .join_safely(Path::new(dest).normalize()) |
Comment on lines
+1928
to
+1938
| .source(&custom) | ||
| .options(vec!["bind".to_string()]) | ||
| .build()?; | ||
| assert!(m.setup_mount(&bind_mount, &options).is_err()); | ||
|
|
||
| let unnormalized_mount = SpecMountBuilder::default() | ||
| .destination(PathBuf::from("/tmp/../proc/custom")) | ||
| .typ("tmpfs") | ||
| .source(PathBuf::from("tmpfs")) | ||
| .build()?; | ||
| assert!(m.setup_mount(&unnormalized_mount, &options).is_err()); |
Member
|
Thank you for the PR. This issue is already addressed in #3846, so this PR is a duplicate. I'll close this PR. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.


Summary
In
Mount::setup_mount()(crates/libcontainer/src/rootfs/mount.rs),self.check_proc_mount(options.root, mount)?was previously only invoked inside theSome("proc" | "sysfs")match arm and was skipped in the wildcard_ =>arm used bybind,tmpfs, and other non-proc/sysfsmount types. In addition,Mount::check_proc_mount()joinedmount.destination()viarootfs.join_safely(dest)without normalizing.or..segments first.This PR:
self.check_proc_mount(options.root, mount)?in the_ =>match arm ofMount::setup_mount()so non-proc/sysfsmounts targeting/procor non-whitelisted paths under/procare consistently rejected duringsetup_mount().mount.destination()viaPath::new(dest).normalize()inMount::check_proc_mount()(and in the/devdestination comparison insetup_mount()) so destinations containing.or..segments (e.g.,/tmp/../proc/custom) cannot bypass the/procprefix check.setup_mount_non_proc_fails_on_denied_proc_destination) covering both directbindmounts and un-normalizedtmpfsmount destinations targeting/proc/customthroughMount::setup_mount().